package com.tools.ad.util;

import android.app.Activity;
import android.view.WindowManager;

/**
 * desc:
 * date: 2018/3/6
 * author: ancun
 */

public class WindowLayoutParamsUtil {


    /**
     * 设置Activity 锁屏可显示
     *
     * @param activity
     * @param keepScreenOn 是否要点亮屏幕
     */
    public static void setWindowShowWhenLocked(Activity activity, boolean keepScreenOn) {
        if (keepScreenOn) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

        } else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        }
    }
}
